#include "./source/Server.hpp"

void OnConnected(const Connection::connection_ptr& connetion)
{
    DEBUG_LOG("new connection:%p", connetion.get());
}

void OnClosed(const Connection::connection_ptr& connetion)
{
    DEBUG_LOG("close connection:%p", connetion.get());
}

void OnMessage(const Connection::connection_ptr& connection, Buffer* buf)
{
    std::string clientmessage;
    buf->Read(&clientmessage, buf->GetReadableSize());
    DEBUG_LOG("%s", clientmessage.c_str());
    std::string str = "Hello Client!";
    connection->Send(str.c_str(), str.length());
}

int main()
{
    TcpServer server(8888);
    server.SetThreadCount(2);
    // server.EnableInactiveRelease(10);
    server.SetMessageCallback(OnMessage);
    server.SetClosedCallback(OnClosed);
    server.SetConnectedCallback(OnConnected);
    server.Start();

    return 0;
}
